const http = require("http");


//跨域问题，不同的协议、IP、端口下的页面发起http请求，会出现跨域问题
http.createServer((req,res)=>{
    if(req.url == '/'){
        var str = "";
        req.on("data",(chunk)=>{
            str += chunk;
        });
        req.on("end",(chunk)=>{   
            var arr = str.split("\r\n");
            var index = arr.indexOf("");
            var index2 = arr.indexOf("",index+1);
            var obj = {username:arr[index+1],age:arr[index2+1]};
            //设置允许跨域
            res.setHeader("Access-Control-Allow-Origin","*");
            res.writeHead(200,{"Content-Type":"text/plain"});
            res.end("received");
            console.log(str);
        })
    }
}).listen(8000);
console.log("server is listening 8000");